#include <tsin/library/BulletLinePlacer.hpp>

#include <tsin/runtime/BulletRuntime.hpp>
#include <tsin/util/Logger.hpp>

#include <cstring>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace tsin;

void BulletLinePlacer::init(float startX, float startY, float angle, float interval)
{
        this->x = startX;
        this->y = startY;
        this->interval = interval;
        this->angle = angle;
}

void BulletLinePlacer::reinit()
{
        float arg1 = arguments[0]->getFloat();
        float arg2 = arguments[1]->getFloat();
        float arg3 = arguments[2]->getFloatInRad();
        float arg4 = arguments[3]->getFloat();

        switch(nrArguments) {
        case 4:
                if (strcmp(desp, "NNNN") == 0)
                        init(arg1, arg2, arg3, arg4);
                break;
        }
}

void BulletLinePlacer::reset()
{
        count = 0;
}

void BulletLinePlacer::place(BulletRuntime *bullet, void *)
{
        bullet->x = x - count * interval * sin(angle);
        bullet->y = y + count * interval * cos(angle);
        bullet->angle = angle;
        count ++;
}

DynamicObject *bindLinePlacer()
{
        return new BulletLinePlacer;
}
